const { get, post } = require('../../request/index')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: String,
      observer: function(newVal, oldVal, changePath) {
        this.setData({
          display: newVal
        })
      }
    },

    net: {
      type: Object,
      observer: function(newVal, oldVal, changedPath) {
        this.getList(newVal)
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    
      show:false,
      mainActiveIndex: 0,
      activeId: [],
      orgNameList:[],
      deIdList:[],
      max: 1000,
      items: []
    },
  
   
  

  /**
   * 组件的方法列表
   */
  methods: {

    onClickNav({ detail = {} }) {
      console.log(detail);
      const { mainActiveIndex } = this.data;
      this.setData({
        mainActiveIndex: detail.index || 0,
      });
      console.log(mainActiveIndex);
    },
  
    onClickItem({ detail = {} }) {

      console.log(detail);

      let list = []
      list.push(detail)

      console.log(list);

      const { activeId,orgNameList,deIdList } = this.data;
  
      const index = activeId.indexOf(detail.id);
      if (index > -1) {
        activeId.splice(index, 1);
      } else {
        activeId.push(detail.id);
        orgNameList.push(detail.orgName)
        deIdList.push(detail.deId)
      }
  
      this.setData({ activeId });


      console.log(activeId);
      if(activeId.length==0){
        this.setData({
          orgNameList:[]
        })
      }
      
    },

    close(){
     
      let a = this.data.activeId.toString()
 
      let arr = [...new Set(this.data.orgNameList)]
      
      let arra =  [...new Set(this.data.deIdList)]
            
             
      let b = arr.toString()
      let c = arra.toString()
      let obj = {
        a:a,
        b:b,
        c:c
      }
      
      this.setData({ show: false })
      this.triggerEvent('changea', obj);
    },

    onClose() {
      this.setData({ show: false })
     

    },
    bindtap() {
      this.setData({ show: true })
      
    },

    async getList(net){

      console.log(net);

      const { url, data} = net
      if (data.mineId == true) {
        let prolist =  wx.getStorageSync('prolist')==''?wx.getStorageSync('prolist'):JSON.parse(wx.getStorageSync('prolist'))
        data.mineId = prolist.mineId
      }
      var res = ""
    
        res = await post(url, data)

       


             
         this.setData({
          items:res.data
         })

        
               

      
        
    }

  }
  
})
